<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="js/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootoast.css">
    <script src="js/jquery-3.6.0.min.js" type="text/javascript"></script>
    <script src="js/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="js/bootoast.js" type="text/javascript"></script>
    <style>
        .container-fluid{
            padding-left: 0px;
            padding-right: 0px;
        }
        .form-group{
            margin: 50px auto;
        }
        .btn{
            margin-right: 50px;
        }
    </style>
    <script>
        $(function(){
            $('#btnEdit').click(function(){
                var oldPass = $('#oldPass').val();
                var newPass = $('#newPass').val();
                var confirmPass = $('#confirmPass').val();
                
                if(oldPass == ''){
                    bootoast({
                        message:'原始密码不能为空',
                        type:'danger',
                        position:'top',
                        timeout:2
                    });
                    return;
                }

                if(newPass == ''){
                    bootoast({
                        message:'新密码不能为空',
                        type:'danger',
                        position:'top',
                        timeout:2
                    });
                    return;
                }

                if(newPass != confirmPass){
                    bootoast({
                        message:'两次输入的密码不一样',
                        type:'danger',
                        position:'top',
                        timeout:2
                    });
                    return;
                }
                if(confirmPass != '' && newPass.length<6){
                    bootoast({
                        message:'新密码不安全，长度不足',
                        type:'danger',
                        position:'top',
                        timeout:2
                    });
                    return;
                }

                $.ajax({
                    url:'modify_pass',
                    type:'post',
                    cache:false,
                    data:{
                        oldPass:$('#oldPass').val(),
                        newPass:$('#newPass').val(),
                        confirmPass:$('#confirmPass').val(),
                    },
                    dataType:'json',
                    success:function (rst) {
                        if(rst.code==-1){
                            bootoast({
                                message:rst.msg,
                                type:'danger',
                                position:'top',
                                timeout:2
                            });
                        }else {
                            bootoast({
                                message:rst.msg+",请重新登录",
                                type:'success',
                                position:'top',
                                timeout:2
                            });
                            $('#oldPass').val('');
                            $('#newPass').val('');
                            $('#confirmPass').val('');
                        }
                    }
                })
            });
        });
    </script>
</head>
<body>
    <div class="container-fluid">
        <ul class="breadcrumb">
            <li><a href="#">首页</a></li>
            <li><a href="#">个人中心</a></li>
            <li>修改密码</li>
        </ul>
        <div class="row">
            <div class="col-sm-8 col-sm-offset-2">
                <form>
                    <div class="form-group">
                        <label for="oldPass">原始密码</label>
                        <input type="password" name="" id="oldPass" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="newPass">新密码</label>
                        <input type="password" name="" id="newPass" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="confirmPass">确认密码</label>
                        <input type="password" name="" id="confirmPass" class="form-control">
                    </div>
                    <div class="form-group text-center">
                        <input type="button" value="修   改" id="btnEdit" class="btn btn-primary">
                        <input type="reset" value="清   空" class="btn btn-default">
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>
</html>